import matplotlib.pyplot as plt
import numpy as np
from forData import pre_process




def draw_pitch_pic(pitch_sum: list, begin=0, end=100):
    plt.figure(figsize=(8, 6))
    plt.bar(range(begin, end), pitch_sum[begin:end])
    plt.ylabel('times', fontsize=20)
    # plt.xlabel('pitch', fontsize=20)
    plt.xticks(fontsize=15)
    plt.yticks(fontsize=12)
    plt.title("")
    plt.show()


def draw_duration_pic(duration_sum: list, begin=0, end=40):
    plt.figure(figsize=(8, 6))
    x = np.arange(begin, end/4, 0.25)
    plt.bar(x, duration_sum[begin:end], width=0.1)
    plt.ylabel('times', fontsize=20)
    # plt.xlabel('duration', fontsize=20)
    plt.xticks(fontsize=15)
    plt.yticks(fontsize=12)
    # plt.title("pure RMC")
    plt.show()


def draw_rest_pic(rest_sum: list, begin=0, end=40):
    plt.figure(figsize=(8, 6))
    x = np.arange(begin, end/2, 0.5)
    plt.bar(x, rest_sum[begin:end])
    plt.ylabel('times', fontsize=20)
    # plt.xlabel('rest', fontsize=20)
    plt.xticks(fontsize=15)
    plt.yticks(fontsize=12)
    # plt.title("pure RMC")
    plt.show()





def stat_pitch_sum(tuplt_list, init_list: list = None):
    this_pitch_list = tuplt_list
    pitch_list_sum = None

    if init_list == None:
        pitch_list_sum = list()
        for i in range(200):
            pitch_list_sum.append(0)
    # init

    else:
        pitch_list_sum = init_list

    for p in this_pitch_list:
        pitch_list_sum[int(p)] += 1

    return pitch_list_sum


def stat_duration_sum(tuplt_list, init_list: list = None):
    this_pitch_list = tuplt_list
    duration_list_sum = None

    if init_list == None:
        duration_list_sum = list()
        # 图表无法显示出来的极少数持续时间会到达15到20的区间，因此取大小为80的数组计数
        for i in range(200):
            duration_list_sum.append(0)
    # init

    else:
        duration_list_sum = init_list

    for p in this_pitch_list:
        duration_list_sum[int(p*4)] += 1

    return duration_list_sum


def stat_rest_sum(tuplt_list, init_list: list = None):
    this_pitch_list = tuplt_list
    rest_list_sum = None

    if init_list == None:
        rest_list_sum = list()
        # 同理，图表无法显示出来的极少数持续时间会到达20到40的区间，因此取大小为80的数组计数
        for i in range(200):
            rest_list_sum.append(0)
    # init

    else:
        rest_list_sum = init_list

    for p in this_pitch_list:
        rest_list_sum[int(p*2)] += 1

    return rest_list_sum


# raw_data0 =pre_process(r"C:\Users\31956\Documents\coding\tf-gan\src\src\save_\24_02_06\24_02_06_11_30_10\epoch20_gen_data_0.npy")
# raw_data1 =pre_process(r"C:\Users\31956\Documents\coding\tf-gan\src\src\save_\24_02_06\24_02_06_11_30_10\epoch20_gen_data_1.npy")
# raw_data2 =pre_process(r"C:\Users\31956\Documents\coding\tf-gan\src\src\save_\24_02_06\24_02_06_11_30_10\epoch20_gen_data_2.npy")
# raw_data3 =pre_process(r"C:\Users\31956\Documents\coding\tf-gan\src\src\save_\24_02_06\24_02_06_11_30_10\epoch20_gen_data_3.npy")
# raw_data4 =pre_process(r"C:\Users\31956\Documents\coding\tf-gan\src\src\save_\24_02_06\24_02_06_11_30_10\epoch20_gen_data_4.npy")
# raw_data5 =pre_process(r"C:\Users\31956\Documents\coding\tf-gan\src\src\save_\24_02_06\24_02_06_11_30_10\epoch20_gen_data_5.npy")
r_list = list()
# random_data=np.load(r'C:\Users\31956\Documents\coding\tf-gan\src\data\random800_20_6v5.npy',allow_pickle=True).tolist()
raw_data0=pre_process(r"C:\Users\31956\Documents\coding\tf-gan\src\data\random800_20_6v5.npy")


# 音高
# for times in range(raw_data0.shape[0]):
#     r_list.extend(raw_data0[times].T[3])
# for times in range(raw_data0.shape[0]):
#     r_list.extend(raw_data1[times].T[3])
# for times in range(raw_data0.shape[0]):
#     r_list.extend(raw_data2[times].T[3])
# for times in range(raw_data0.shape[0]):
#     r_list.extend(raw_data3[times].T[3])
# for times in range(raw_data0.shape[0]):
#     r_list.extend(raw_data4[times].T[3])
# for times in range(raw_data0.shape[0]):
#     r_list.extend(raw_data5[times].T[3])
# sum_list = stat_pitch_sum(r_list)
# sum_list=stat_pitch_sum(r_list,init_list=sum_list)
# draw_pitch_pic(sum_list, begin=0, end=100)

# 持续时间（0.25为间隔，范围设置为0到10）
# for times in range(raw_data0.shape[0]):
#     r_list.extend(raw_data0[times].T[4])
# for times in range(raw_data0.shape[0]):
#     r_list.extend(raw_data1[times].T[4])
# for times in range(raw_data0.shape[0]):
#     r_list.extend(raw_data2[times].T[4])
# for times in range(raw_data0.shape[0]):
#     r_list.extend(raw_data3[times].T[4])
# for times in range(raw_data0.shape[0]):
#     r_list.extend(raw_data4[times].T[4])
# for times in range(raw_data0.shape[0]):
#     r_list.extend(raw_data5[times].T[4])
# sum_list = stat_duration_sum(r_list)
# draw_duration_pic(sum_list, begin=0, end=40)

# 休止符（0.5为间隔，范围设置为0到20）
for times in range(raw_data0.shape[0]):
    r_list.extend(raw_data0[times].T[5])
# for times in range(raw_data0.shape[0]):
#     r_list.extend(raw_data1[times].T[5])
# for times in range(raw_data0.shape[0]):
#     r_list.extend(raw_data2[times].T[5])
# for times in range(raw_data0.shape[0]):
#     r_list.extend(raw_data3[times].T[5])
# for times in range(raw_data0.shape[0]):
#     r_list.extend(raw_data4[times].T[5])
# for times in range(raw_data0.shape[0]):
#     r_list.extend(raw_data5[times].T[5])
sum_list = stat_rest_sum(r_list)
draw_rest_pic(sum_list, begin=0, end=20)


